package storage

import (
	"context"
	"fmt"
	"github.com/starmotioncf/common/storage"
	"github.com/starmotioncf/common/storage/s3"
	"time"
)

type Config struct {
	Avatar s3.Config // 上传存储头像， 用的s3
}

type Bucket string

const (
	Avatar Bucket = "avatar" //上传头像
)

type Storage struct {
	fs map[Bucket]storage.FileSystem
}

func NewStorage(cfg Config) (s *Storage, err error) {
	fs := make(map[Bucket]storage.FileSystem)
	fs[Avatar], err = s3.NewS3(cfg.Avatar)
	s = &Storage{
		fs: fs,
	}
	return
}

func (s *Storage) GetPresignedURL(ctx context.Context, bucket Bucket, key string, ts time.Duration) (url string, err error) {
	f, ok := s.fs[bucket]
	if !ok {
		return "", fmt.Errorf("bucket not found")
	}
	return f.PresignUpload(ctx, key, ts)
}
